﻿/**
 * @package ZMenFM.Utils
 * @brief ZMAeroHelper
 * 窗口Aero效果帮助类
 * 
 * @date 07/21/2012
 * @refer http://www.cnblogs.com/zhouyinhui/archive/2007/06/16/785920.html
 * 
 */
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Interop;
using System.Windows.Forms;

namespace ZMenFM.Utils.UI.Aero
{
    public class ZMAeroHelper
    {
        public static bool ExtendGlassFrame(Window window, Thickness margin)
        {
            if (!ZMDwmAPI.DwmIsCompositionEnabled())
                return false;

            IntPtr hwnd = new WindowInteropHelper(window).Handle;
            if (hwnd == IntPtr.Zero)
                throw new InvalidOperationException("The Window must be shown before extending glass.");

            // Set the background to transparent from both the WPF and Win32 perspectives
            window.Background = Brushes.Transparent;
            HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;

            ZMDwmAPI.MARGINS margins = new ZMDwmAPI.MARGINS((int)margin.Left, (int)margin.Top, (int)margin.Right, (int)margin.Bottom);
            ZMDwmAPI.DwmExtendFrameIntoClientArea(hwnd, margins);

            return true;
        }
    }
}
